package cn.com.zhangwoo.microstar.adapter;

import android.annotation.SuppressLint;
import android.app.ActionBar.LayoutParams;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
import cn.com.microstar.activity.R;
import cn.com.zhangwoo.microstar.http.VolleySingleton;
import cn.com.zhangwoo.microstar.inteface.IUtilDB;

public class GalleryAdapter extends BaseAdapter {
	private String[] imageUrls; 
	private Context context;
	private int mGalleryItemBackground=0x0000;
	private com.android.volley.toolbox.ImageLoader mImageLoader;
	public GalleryAdapter(String[] imageUrls, Context context) {
		this.imageUrls = imageUrls;
		this.context = context;
		mImageLoader=VolleySingleton.getVolleySingleton(context).getImageLoader();
	}

	public int getCount() {
		return Integer.MAX_VALUE;
	}

	public Object getItem(int position) {
		return imageUrls[position];
		//return IUtilDB._TOPHOMEPAGEIMG[position];
	}

	public long getItemId(int position) {
		return position;
	}

	@SuppressLint("InlinedApi") public View getView(int position, View convertView, ViewGroup parent) {
		ImageView view = new ImageView(context);
		int s=(position%imageUrls.length);
		try {
			try {
				if(imageUrls.length>0)
				{
					
					mImageLoader.get(imageUrls[s], 
						com.android.volley.toolbox.ImageLoader.getImageListener(view,R.drawable.zhangwo_hometop2, R.drawable.zhangwo_hometop2));
				}
			} catch (Exception e) {
				view.setImageResource(IUtilDB._TOPHOMEPAGEIMG[s]);
			}
			view.setScaleType(ImageView.ScaleType.FIT_XY);
			view.setLayoutParams(new Gallery.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
			view.setBackgroundResource(mGalleryItemBackground);
		} catch (Exception e) {
			view.setImageResource(IUtilDB._TOPHOMEPAGEIMG[s]);
		}
		return view;
	}

}
